package uk.org.landeg.euler.problems;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;

public class Problem039 extends AbstractProblem{
	public static void main(String[] args) {
		ProblemLauncher launcher = new ProblemLauncher(new Problem039());
		launcher.solve();		
	}

	@Override
	public String getDescription() {
		return "For which value of p  1000, is the number of solutions maximised?";
	}

	@Override
	public Integer getProblemNumber() {
		return 39;
	}

	@Override
	public Object solve() {
		int max = 0;
		int sol = 0;
		int pMax = 0;
		int c;
		for (int i = 120 ; i < 1000 ; i++) {
			sol = 0;
			for (int a = 1 ; a < i ; a++) {
				for (int b = 1; b <= a ; b++) {
					c = i - a -b;
					if (a*a + b*b == c*c) {
						sol++;
					}
				}
			}
			if (sol > max) {
				notes.add("new max found at P=" + i + "(" + sol + ")");
				max = sol;
				pMax = i;
			}
		}
		return pMax;
	}
}
